<?php
if ($argc < 2 ) {
  die("\n\t\tUsage: " . $argv[0]. "  /path/to/libs/");
}

$libsDir = $argv[1];
if ( $libsDir[strlen($libsDir)-1] != "/" ) $libsDir .= "/";

$finalDest = $libsDir . "drylamp/";

if (is_dir($finalDest)) {
  echo "Found previous installation of drylamp at $finalDest\n";
  if ($argv[2] == "-f") {
    echo "Erasing previous installation\n";
    shell_exec("rm -Rdf ". $finalDest);
  }
   else die("Use -f option to force reinstallation\n");
}

echo "Checking out the source code ...";
$output = shell_exec("svn checkout http://drylamp.googlecode.com/svn/trunk/ " . $libsDir );
echo "OK\n";

echo "Setting permissions ...";
shell_exec( "chmod 0777 " . $finalDest. "smarty_ext/cache/"  );
shell_exec( "chmod 0777 ". $finalDest. "smarty_ext/compile/" );
echo "OK\n";